package version1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import condorAPI.Condor;
import condorAPI.CondorException;
import condorAPI.JobDescription;

public class CondorHandler{
	private Condor condor = new Condor();
	private List<String> coreFilteringList = new ArrayList<String>();
	private List<String> jobFilteringList = new ArrayList<String>();
	
	public CondorHandler() {
		coreFilteringList = Arrays.asList(CompleteTableNames.fullCoreList);
		jobFilteringList = Arrays.asList(CompleteTableNames.fulljobList);
	}
	
	public void condorStatus() {
		try {
			condor.status(coreFilteringList);
		} catch (CondorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	/**
	 * Submit job using an existing submit file
	 * @param submitFile
	 */
	public void submitJob(String submitFile) {
		try {
			JobDescription jd = new JobDescription(submitFile);
			System.out.println("Submitting job using submit file: "+submitFile);
			condor.submit(jd);
		} catch (CondorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * Submits a job with given data
	 * @param executable
	 * @param universe
	 * @param arguments
	 * @param outputFile empty string if none is chosen
	 * @param inputFile empty string if none is chosen
	 */
	public void submitJob(String executable, String universe, String arguments,
			String outputFile, String inputFile) {
		JobDescription jd = new JobDescription();
		try {
			jd.addAttribute("Executable", executable);
			jd.addAttribute("Universe", universe);
			if (!inputFile.equals("")) jd.addAttribute("Input", inputFile);
			if (!outputFile.equals("")) jd.addAttribute("Output", outputFile);
			jd.addAttribute("Arguments", arguments);
			System.out.println("Submitting job: Exe="+executable+" Uni="+universe+
					" args="+arguments+" out="+outputFile+" in="+inputFile);
			condor.submit(jd);
		} catch (CondorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public List<String> getCoreFilteringList() {
		return coreFilteringList;
	}
	
	public void setCoreFilteringList(List<String> list) {
		coreFilteringList = list;
	}
	public List<String> getJobFilteringList(){
		try {
			condor.status(coreFilteringList);
		} catch (CondorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jobFilteringList;
	}
}
